import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

import GameElements.CTDCreep;



/**
 * 
 */

/**
 * @author Dogan
 *
 */
public class TDGameWindow extends GameWindow {

	private static final long serialVersionUID = 1L;
	
	
	private TDGamePanel panel;
	private MenuPanel menu;
	private Container contentPane;
	private JPanel glassPane;
	private Image heart;
	private Image gold;
	private int health;
	private int money;
	private Controller controller;
	private Image[] monsters = new Image[5];
	private ArrayList<CTDCreep> creeps = new ArrayList<CTDCreep>();
	

	public TDGameWindow(){
		super("Tower Defense Gruppe 96");
	}
	public TDGameWindow(String windowTitle) {
		super(windowTitle);
	}
	
	public TDGameWindow(String string, Controller controller2) {
		super(string);
		setController(controller2);
		controller = controller2;
		heart = new ImageIcon("images/heart.png").getImage();
		gold = new ImageIcon("images/gold.png").getImage();
		monsters[0] = new ImageIcon("images/defaultskin/monsters/monster.png").getImage();
		monsters[1] = new ImageIcon("images/defaultskin/monsters/monster_red.png").getImage();
		monsters[2] = new ImageIcon("images/defaultskin/monsters/monster_blue.png").getImage();
		monsters[3] = new ImageIcon("images/defaultskin/monsters/monster_black.png").getImage();
		monsters[4] = new ImageIcon("images/defaultskin/monsters/monster_mult.png").getImage();
	}
	@Override
	public void paint(Graphics g){
		super.paint(g);
		g.setFont(new Font("Arial", Font.BOLD, 16));
		g.setColor(Color.WHITE);
		
		g.drawImage(heart, this.getWidth()-50, 20, 25, 25, null);
		health = controller.getHealth();
		g.drawString(""+health, this.getWidth()-50, 60);
		
		g.drawImage(gold, this.getWidth()-50, this.getHeight()-50, 25, 25, null);
		money = controller.getGold();
		g.drawString(""+money, this.getWidth()-50, this.getHeight()-10);
		
		Iterator<CTDCreep> iteCreeps = creeps.iterator();
		while(iteCreeps.hasNext()){
			CTDCreep actCreep = iteCreeps.next();
			g.drawImage(monsters[actCreep.getCreeptyp()-1],actCreep.getAbsoluteX()+10, actCreep.getAbsoluteY()+10, 18, 18, null);
		}
	}

	/* (non-Javadoc)
	 * @see GameWindow#createGamePanel()
	 */
	@Override
	protected GamePanel createGamePanel() {
		contentPane = this.getContentPane();
		contentPane.setBackground(Color.BLACK);
		panel = new TDGamePanel(this, contentPane);
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.LINE_AXIS));
		contentPane.add(panel);
		
		menu = new MenuPanel();
		menu.setPreferredSize(new Dimension(50, 350));
		menu.setMaximumSize(new Dimension(50, 350));
		menu.setLocation(this.getWidth()-50, this.getHeight());
		menu.setVisible(true);
		contentPane.add(menu);
		contentPane.validate();
		return panel;
		
	}
	public void setMap(char[][] _mapElements)
	{
		panel.setMap(_mapElements);
		panel.setGamePanelContents();
		pack();
	}
	
	public void drawCreeps(ArrayList<CTDCreep> creeps){
		this.creeps = creeps;
		
	}

	/**
	 * @return the controller
	 */
	public Controller getController() {
		return panel.getController();
	}


	/**
	 * @param controller the controller to set
	 */
	public void setController(Controller controller) {
		this.panel.setController(controller);
		this.menu.setController(controller);
	}
	public void AddTower(int x,int y, int towerid)
	{
		panel.AddTower(x, y, towerid);
	}

	public static void main(String[] args){
		TDGameWindow wnd = new TDGameWindow();
		wnd.setVisible(true);
		wnd.setSize(800, 600);
		wnd.setLocationRelativeTo(null);
	}
	
	

}
